// Copyright 2013 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
 *
 * @fileoverview Public domain parameters for NIST curves.
 * @author thaidn@google.com (Thai Duong)
 */

goog.provide('e2e.ecc.constant');
goog.provide('e2e.ecc.constant.CURVE_25519');
goog.provide('e2e.ecc.constant.P_256');
goog.provide('e2e.ecc.constant.P_384');


/**
 * The field order, e.g., 2^224 (2^32 - 1) + 2^192 + 2^96 - 1.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_256.Q = [
    0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];


/**
 * The B coefficient in the equation of the elliptic curve.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_256.B = [
   0x5A, 0xC6, 0x35, 0xD8, 0xAA, 0x3A, 0x93, 0xE7,
   0xB3, 0xEB, 0xBD, 0x55, 0x76, 0x98, 0x86, 0xBC,
   0x65, 0x1D, 0x06, 0xB0, 0xCC, 0x53, 0xB0, 0xF6,
   0x3B, 0xCE, 0x3C, 0x3E, 0x27, 0xD2, 0x60, 0x4B];


/**
 * The base point in uncompressed form.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_256.G = [0x04, /* uncompressed */
   // x
   0x6B, 0x17, 0xD1, 0xF2, 0xE1, 0x2C, 0x42, 0x47,
   0xF8, 0xBC, 0xE6, 0xE5, 0x63, 0xA4, 0x40, 0xF2,
   0x77, 0x03, 0x7D, 0x81, 0x2D, 0xEB, 0x33, 0xA0,
   0xF4, 0xA1, 0x39, 0x45, 0xD8, 0x98, 0xC2, 0x96,
   // y
   0x4F, 0xE3, 0x42, 0xE2, 0xFE, 0x1A, 0x7F, 0x9B,
   0x8E, 0xE7, 0xEB, 0x4A, 0x7C, 0x0F, 0x9E, 0x16,
   0x2B, 0xCE, 0x33, 0x57, 0x6B, 0x31, 0x5E, 0xCE,
   0xCB, 0xB6, 0x40, 0x68, 0x37, 0xBF, 0x51, 0xF5];


/**
 * The order of the base point.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_256.N = [
   0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
   0xBC, 0xE6, 0xFA, 0xAD, 0xA7, 0x17, 0x9E, 0x84,
   0xF3, 0xB9, 0xCA, 0xC2, 0xFC, 0x63, 0x25, 0x51];


/**
 * The field order 2^384 - 2^128 - 2^196 + 2^32 - 1
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_384.Q = [
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff];


/**
 * The B coefficient in the equation of the elliptic curve.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_384.B = [
   0xb3, 0x31, 0x2f, 0xa7, 0xe2, 0x3e, 0xe7, 0xe4,
   0x98, 0x8e, 0x05, 0x6b, 0xe3, 0xf8, 0x2d, 0x19,
   0x18, 0x1d, 0x9c, 0x6e, 0xfe, 0x81, 0x41, 0x12,
   0x03, 0x14, 0x08, 0x8f, 0x50, 0x13, 0x87, 0x5a,
   0xc6, 0x56, 0x39, 0x8d, 0x8a, 0x2e, 0xd1, 0x9d,
   0x2a, 0x85, 0xc8, 0xed, 0xd3, 0xec, 0x2a, 0xef];


/**
 * The base point in uncompressed form.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_384.G = [0x04, /* uncompressed */
   // x
   0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37,
   0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74,
   0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98,
   0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38,
   0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c,
   0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xB7,
   // y
   0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f,
   0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29,
   0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c,
   0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0,
   0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d,
   0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f];


/**
 * The order of the base point.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.P_384.N = [
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0xc7, 0x63, 0x4d, 0x81, 0xf4, 0x37, 0x2d, 0xdf,
  0x58, 0x1a, 0x0d, 0xb2, 0x48, 0xb0, 0xa7, 0x7a,
  0xec, 0xec, 0x19, 0x6a, 0xcc, 0xc5, 0x29, 0x73];


/**
 * The field order for Curve25519: 2^255 - 19.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.CURVE_25519.Q = [
  0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x100 - 19];


/**
 * The order of the base point.
 * @type {e2e.ByteArray}
 */
e2e.ecc.constant.CURVE_25519.N = [
  0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x14, 0xde, 0xf9, 0xde, 0xa2, 0xf7, 0x9c, 0xd6,
  0x58, 0x12, 0x63, 0x1a, 0x5c, 0xf5, 0xd3, 0xed];
